
<style>
  /* 这段样式只是用于演示 */
  #layuiadmin-form-dbdepot .layui-icon{
    font-size: 30px;
    color: #1e9fff;
  }
</style>


<div class="layui-form" id="layuiadmin-form-dbdepot" lay-filter="layuiadmin-form-dbdepot" style="padding: 20px 0 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">库名称</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="name" value="{{ d.params.name || '' }}" lay-verify="required|nameIsKeyWord" placeholder="数据库库名称(类似表空间名)" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="name"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">文件存储时间(天)</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="days" value="{{ d.params.days || '' }}" lay-verify="numberAndNullAndNull" placeholder="一个数据文件存储数据的时间跨度，单位为天，默认值：10。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="days"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">数据保留时间(天)</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="keep" value="{{ d.params.keep || '' }}"  lay-verify="numberAndNullAndNull" placeholder="数据库中数据保留的天数，单位为天，默认值：3650。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="keep"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">记录最小条数</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="minRows" value="{{ d.params.minRows || '' }}" lay-verify="numberAndNullAndNull" placeholder="文件块中记录的最小条数，单位为条，默认值：100。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="minRows"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">记录最大条数</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="maxRows" value="{{ d.params.maxRows || '' }}" lay-verify="numberAndNull" placeholder="文件块中记录的最大条数，单位为条，默认值：4096。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="maxRows"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">文件压缩标志位</label>
    <div class="layui-input-inline">
<!--      文件压缩标志位，0：关闭，1:一阶段压缩，2:两阶段压缩。默认值：2-->
      <script type="text/html" template>
        <select name="comp" lay-verify="">
          <option value="" >使用服务端默认值</option>
          <option value="0" {{  d.params.comp === '0' ? 'selected' : '' }} >关闭</option>
          <option value="1" {{  d.params.comp === '1' ? 'selected' : '' }} >一阶段压缩</option>
          <option value="2" {{  d.params.comp === '2' ? 'selected' : '' }} {{  d.params.comp || 'selected' || '' }} >两阶段压缩</option>
        </select>
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="comp"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">WAL级别(乱选会报错)</label>
    <div class="layui-input-inline">
<!--      1：写wal, 但不执行fsync; 2：写wal, 而且执行fsync。默认值：1。-->
      <script type="text/html" template>
        <select name="walLevel" lay-verify="">
          <option value=""  {{  d.params.walLevel || 'selected' || '' }} >使用服务端默认值</option>
          <option value="0" {{  d.params.walLevel === '0' ? 'selected' : '' }}  >不写wal</option>
          <option value="1" {{  d.params.walLevel === '1' ? 'selected' : '' }}  >写wal, 但不执行fsync</option>
          <option value="2" {{  d.params.walLevel === '2' ? 'selected' : '' }}  >写wal, 而且执行fsync</option>
        </select>
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="walLevel"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">fsync周期</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="fsync" value="{{ d.params.fsync || '' }}" lay-verify="numberAndNull" placeholder="当wal设置为2时，执行fsync的周期。设置为0，表示每次写入，立即执行fsync。单位为毫秒，默认值：3000。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="fsync"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">内存块的大小（MB）</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="cache" value="{{ d.params.cache || '' }}" lay-verify="numberAndNull" placeholder="内存块的大小，单位为兆字节（MB），默认值：16。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="cache"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">内存块数量</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="blocks" value="{{ d.params.blocks || '' }}" lay-verify="numberAndNull" placeholder="每个VNODE（TSDB）中有多少cache大小的内存块。因此一个VNODE的用的内存大小粗略为（cache * blocks）。单位为块，默认值：4。" autocomplete="off" class="layui-input">
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="blocks"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">副本个数</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <select name="replica" lay-verify="">
          <option value="" >使用服务端默认值</option>
          <option value="1" {{  d.params.replica === '1' ? 'selected' : '' }} {{  d.params.replica || 'selected' || '' }} >1个</option>
          <option value="2" {{  d.params.replica === '2' ? 'selected' : '' }}  >2个</option>
          <option value="3" {{  d.params.replica === '3' ? 'selected' : '' }}  >3个</option>
        </select>
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="replica"></i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">时间戳精度标识</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <select name="precision" lay-verify="">
          <option value="" >使用服务端默认值</option>
          <option value="ms" {{  d.params.precision === 'ms' ? 'selected' : '' }} {{  d.params.precision || 'selected' || '' }} >毫秒</option>
          <option value="us" {{  d.params.precision === 'us' ? 'selected' : '' }}  >微秒</option>
        </select>
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="precision"></i>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">数据库更新</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <select name="update" lay-verify="">
          <option value="" >使用服务端默认值</option>
          <option value="1" {{  d.params.update === '1' ? 'selected' : '' }} {{  d.params.update || 'selected' || '' }} >允许</option>
<!--          <option value="0" {{  d.params.update === '0' ? 'selected' : '' }}  >不允许</option>-->
        </select>
      </script>
    </div>
    <div class="layui-form-mid">
      <i class="layui-icon layui-icon-tips"  data-type="update"></i>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-dbdepot-front-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form', 'upload'], function(){
  var $ = layui.$
  ,form = layui.form
  ,upload = layui.upload
  ,admin = layui.admin;

  $('#layuiadmin-form-dbdepot .layui-icon').on('click', function(){
    var type = $(this).data('type');
    active[type] && active[type].call(this);
  });

  var active = {
    name: function(){layer.tips('要创建的库名称,请勿乱输,没有做什么检查,全凭自觉', this, {time: 5000});}
   ,days: function(){layer.tips('一个数据文件存储数据的时间跨度，单位为天，默认值：10。', this, {time: 5000});}
   ,keep: function(){layer.tips('数据库中数据保留的天数，单位为天，默认值：3650。', this, {time: 5000});}
   ,minRows: function(){layer.tips('文件块中记录的最小条数，单位为条，默认值：100。', this, {time: 5000});}
   ,maxRows: function(){layer.tips('文件块中记录的最大条数，单位为条，默认值：4096。', this, {time: 5000});}
   ,comp: function(){layer.tips('文件压缩标志位，0：关闭，1:一阶段压缩，2:两阶段压缩。默认值：2。', this, {time: 5000});}
   ,walLevel: function(){layer.tips('WAL级别。1：写wal, 但不执行fsync; 2：写wal, 而且执行fsync。默认值：1。', this, {time: 5000});}
   ,fsync: function(){layer.tips('当wal设置为2时，执行fsync的周期。设置为0，表示每次写入，立即执行fsync。单位为毫秒，默认值：3000。', this, {time: 5000});}
   ,cache: function(){layer.tips('内存块的大小，单位为兆字节（MB），默认值：16。', this, {time: 5000});}
   ,blocks: function(){layer.tips(' 每个VNODE（TSDB）中有多少cache大小的内存块。因此一个VNODE的用的内存大小粗略为（cache * blocks）。单位为块，默认值：4。', this, {time: 5000});}
   ,replica: function(){layer.tips('副本个数，取值范围：1-3。单位为个，默认值：1', this, {time: 5000});}
   ,precision: function(){layer.tips('时间戳精度标识，ms表示毫秒，us表示微秒。默认值：ms', this, {time: 5000});}
   ,update: function(){layer.tips('UPDATE 标志数据库支持更新相同时间戳数据', this, {time: 5000});}
  }
  form.verify({
    numberAndNull: function (value, item) { //value：表单的值、item：表单的DOM对象
      if (value !== '') {
        if (!value || isNaN(value)) {
          return "只能填写数字或 不填使用默认值!!!"
        }
      }
    },
    nameIsKeyWord: function (value, item) { //value：表单的值、item：表单的DOM对象
      if (value !== '') {
          var keywordlist= KeyWordData.data;
            for (const keyword  of  keywordlist){
              // console.log("**************")
              // console.log(keyword)
              // console.log(value.toUpperCase())
              // console.log(value.toUpperCase()===keyword)
              if( value.toUpperCase()===keyword){
                console.log("库名与taos关键字冲突,请更改!!!")
                return "库名与taos关键字冲突,请更改!!!"
              }
            }
      }
    }
    //我们既支持上述函数式的方式，也支持下述数组的形式
    //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
  });

    var KeyWordData =
            {
              "code": 0,
              "msg": "taos的关键字列表",
              "data": [
                "ABLOCKS"
                ,"ABORT"
                ,"ACCOUNT"
                ,"ACCOUNTS"
                ,"ADD"
                ,"AFTER"
                ,"ALL"
                ,"ALTER"
                ,"AND"
                ,"AS"
                ,"ASC"
                ,"ATTACH"
                ,"AVG"
                ,"BEFORE"
                ,"BEGIN"
                ,"BETWEEN"
                ,"BIGINT"
                ,"BINARY"
                ,"BITAND"
                ,"BITNOT"
                ,"BITOR"
                ,"BOOL"
                ,"BOTTOM"
                ,"BY"
                ,"CACHE"
                ,"CASCADE"
                ,"CHANGE"
                ,"CLOG"
                ,"CLUSTER"
                ,"COLON"
                ,"COLUMN"
                ,"COMMA"
                ,"COMP"
                ,"CONCAT"
                ,"CONFIGS"
                ,"CONFLICT"
                ,"CONNECTION"
                ,"CONNECTIONS"
                ,"COPY"
                ,"COUNT"
                ,"CREATE"
                ,"CTIME"
                ,"DATABASE"
                ,"DATABASES"
                ,"DAYS"
                ,"DEFERRED"
                ,"DELIMITERS"
                ,"DESC"
                ,"DESCRIBE"
                ,"DETACH"
                ,"DIFF"
                ,"DISTINCT"
                ,"DIVIDE"
                ,"DNODE"
                ,"DNODES"
                ,"DOT"
                ,"DOUBLE"
                ,"DROP"
                ,"EACH"
                ,"END"
                ,"EQ"
                ,"EXISTS"
                ,"EXPLAIN"
                ,"FAIL"
                ,"FILL"
                ,"FIRST"
                ,"FLOAT"
                ,"FOR"
                ,"FROM"
                ,"GE"
                ,"GLOB"
                ,"GRANTS"
                ,"GROUP"
                ,"GT"
                ,"ID"
                ,"IF"
                ,"IGNORE"
                ,"IMMEDIATE"
                ,"IMPORT"
                ,"IN"
                ,"INITIALLY"
                ,"INSERT"
                ,"INSTEAD"
                ,"INTEGER"
                ,"INTERVAL"
                ,"INTO"
                ,"IP"
                ,"IS"
                ,"ISNULL"
                ,"JOIN"
                ,"KEEP"
                ,"KEY"
                ,"KILL"
                ,"LAST"
                ,"LE"
                ,"LEASTSQUARES"
                ,"LIKE"
                ,"LIMIT"
                ,"LINEAR"
                ,"LOCAL"
                ,"LP"
                ,"LSHIFT"
                ,"LT"
                ,"MATCH"
                ,"MAX"
                ,"METRIC"
                ,"METRICS"
                ,"MIN"
                ,"MINUS"
                ,"MNODES"
                ,"MODULES"
                ,"NCHAR"
                ,"NE"
                ,"NONE"
                ,"NOT"
                ,"NOTNULL"
                ,"NOW"
                ,"OF"
                ,"OFFSET"
                ,"OR"
                ,"ORDER"
                ,"PASS"
                ,"PERCENTILE"
                ,"PLUS"
                ,"PRAGMA"
                ,"PREV"
                ,"PRIVILEGE"
                ,"QUERIES"
                ,"QUERY"
                ,"RAISE"
                ,"REM"
                ,"REPLACE"
                ,"REPLICA"
                ,"RESET"
                ,"RESTRICT"
                ,"ROW"
                ,"ROWS"
                ,"RP"
                ,"RSHIFT"
                ,"SCORES"
                ,"SELECT"
                ,"SEMI"
                ,"SET"
                ,"SHOW"
                ,"SLASH"
                ,"SLIDING"
                ,"SMALLINT"
                ,"SPREAD"
                ,"STABLE"
                ,"STABLES"
                ,"STAR"
                ,"STATEMENT"
                ,"STDDEV"
                ,"STREAM"
                ,"STREAMS"
                ,"STRING"
                ,"SUM"
                ,"TABLE"
                ,"TABLES"
                ,"TAG"
                ,"TAGS"
                ,"TBLOCKS"
                ,"TBNAME"
                ,"TIMES"
                ,"TIMESTAMP"
                ,"TINYINT"
                ,"TOP"
                ,"TRIGGER"
                ,"UMINUS"
                ,"UPLUS"
                ,"USE"
                ,"USER"
                ,"USERS"
                ,"USING"
                ,"VALUES"
                ,"VARIABLE"
                ,"VGROUPS"
                ,"VIEW"
                ,"WAVG"
                ,"WHERE"
              ]
            };

})
</script>